<script>
import axios from "axios";

export default {
  name: "CarouselMap",
  props:['id'],
  data() {
    return {
      list:[],
      loading:false,
    }
  },
  methods:{
    banner(i) {
      console.log(i)
      let div = document.getElementsByClassName("carousel_little_item")
      for (let j = 0; j < div.length; j++) {
        div[j].classList.remove("carousel_item_select")
      }
      div[i].classList.add("carousel_item_select")
    },
    showBigPic(e) {
      let big = document.getElementsByClassName('big_pic')[0]
      big.parentNode.style.display = 'flex'
      big.src = e.target.src
    },
    exitBigPic(e) {
      let div = e.target
      if (div.tagName === 'IMG')
        div = div.parentNode
      div.style.display = 'none'
    },
    selectCarousel(index) {
      this.$refs.carousel.setActiveItem(index)
    },
    getList() {
      this.loading = true

      axios.get(`/api/photo/list/${this.id}`)
          .then(res =>{
            this.loading = false
            if(res.data.code === 0 ) {
              this.list=res.data.data
            }else {
              this.$message.warning(res.data.msg)
              this.$emit('closeMap')
            }
          }).catch(err => this.$message.error(err))
    }
  },
  watch:{
    id: {
      immediate:true,
      handler(value) {
        if(value !== '') {
          this.getList()
        }
      }
    }
  }
}
</script>

<template>
  <div class="carousel_box" v-loading="loading">
    <el-carousel ref="carousel" height="487px" indicator-position="none" :autoplay="false" @change="banner">
      <el-carousel-item v-for="(item,index) in list" :key="index">
        <div class="carousel_item">
          <img alt="" :src="item.src" @click="showBigPic">
        </div>
      </el-carousel-item>
    </el-carousel>
    <div style="background-color: #222327;width: 100%">
      <div class="carousel_little_box">
        <div :class="index === 0?'carousel_little_item carousel_item_select':'carousel_little_item'" @click="selectCarousel(index)" :style="'background-image:'+'url('+item.src+');'" v-for="(item,index) in list" :key="index">
<!--          <img alt="" :src="item" @click="selectCarousel(index)">-->
        </div>
      </div>

    </div>
  </div>

</template>

<style scoped>
.carousel_box {
}

.carousel_item {
  padding-top: 10px;
  height: 100%;
  width: 100%;
  display: flex;
  background-color: #222327;
  position: fixed;
  justify-content: center;
  align-items: center;
  text-align: center;
  overflow: auto;

}


.carousel_item img {
  max-width: 100%;
  max-height: 100%;
  cursor: url("../../assets/img/搜索 (1).png") 16 16, auto;

}

.carousel_little_box {
  padding-top: 10px;
  height: 78px;
  overflow-x: auto;
  margin: 0 auto;
  text-align: center;
  white-space: nowrap;
  width: 90%;
}

.carousel_little_item {
  margin: 0 5px;
  cursor: pointer;
  border: 1px solid #ffffff;
  display: inline-flex;
  height: 65px;
  width: 65px;
  text-align: center;
  justify-content: center;
  background-size:cover;
}

.carousel_little_item img {
  max-width: 100%;
  max-height: 100%;
}

.carousel_item_select {
  border: 2px solid #409EFF;
}
</style>